﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IteratorPattern.Practical.ExtrinsicIterator
{
    /// <summary>
    /// 定義一個具體的聚合類
    /// </summary>
    public class ConcreteAggregate : Aggregate
    {
        //存儲元素的集合
        private object[] objs = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

        /// <summary>
        /// 獲取元素個數
        /// </summary>
        /// <returns></returns>
        public int Size()
        {
            return objs.Length;
        }

        /// <summary>
        /// 獲取指定序號的元素
        /// </summary>
        /// <param name="index">指定的序號</param>
        /// <returns></returns>
        public object GetElement(int index)
        {
            if (index < 0 || index > objs.Length)
            {
                return null;
            }

            return objs[index];
        }

        /// <summary>
        /// 創建該聚合類的迭代器
        /// </summary>
        /// <returns></returns>
        public override Iterator CreateIterator()
        {
            return new ConcreteIterator(this);
        }
    }
}
